package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.domain.entity.TrainHomework;
import com.example.demo.domain.entity.TrainHomeworkProblem;
import com.example.demo.mapper.TrainHomeworkMapper;
import com.example.demo.service.TrainHomeworkProblemService;
import com.example.demo.mapper.TrainHomeworkProblemMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author DaoJia
* @description 针对表【train_homework_problem(培训系统-作业-题目关系)】的数据库操作Service实现
* @createDate 2024-02-02 15:07:40
*/
@Service
public class TrainHomeworkProblemServiceImpl extends ServiceImpl<TrainHomeworkProblemMapper, TrainHomeworkProblem>
    implements TrainHomeworkProblemService{

    @Resource
    private TrainHomeworkProblemMapper trainHomeworkProblemMapper;

    @Override
    public void removeByHwIdAndProblemId(Long homeworkId, List<Long> problemId) {
        QueryWrapper<TrainHomeworkProblem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("homework_id", homeworkId);
        queryWrapper.in("problem_id", problemId);
        trainHomeworkProblemMapper.delete(queryWrapper);
    }

    @Override
    public List<TrainHomeworkProblem> queryByHwId(Long homeworkId) {
        QueryWrapper<TrainHomeworkProblem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("homework_id", homeworkId);
        return trainHomeworkProblemMapper.selectList(queryWrapper);
    }

    @Override
    public void deleteByHwId(Long homeworkId) {
        QueryWrapper<TrainHomeworkProblem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("homework_id", homeworkId);
        trainHomeworkProblemMapper.delete(queryWrapper);

    }

    @Override
    public void deleteByProblemIds(List<Long> problemIds) {
        if (CollectionUtils.isEmpty(problemIds)){
            return;
        }
        QueryWrapper<TrainHomeworkProblem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("problem_id", problemIds);
        trainHomeworkProblemMapper.delete(queryWrapper);
    }

    @Override
    public List<TrainHomeworkProblem> queryByHwIds(List<Long> homeworkIds) {
        if (CollectionUtils.isEmpty(homeworkIds)){
            return new ArrayList<>();
        }
        QueryWrapper<TrainHomeworkProblem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("homework_id", homeworkIds);
        return trainHomeworkProblemMapper.selectList(queryWrapper);
    }
}




